/*
 * main.c
 *
 *  Created as a sandbox, please feel free to hack away at this...
 *
 *
 *
 *
 */

#include<stdio.h>
#include<stdlib.h>
#include "System Timer/system_timer.h"
#include "CPU/cpu.h"
#include "Shared Memory/memory.h"
#include "IO Devices/io_device.h"
#include "Utility/Queue.h"
#include "Processes/process_type.h"




/* Test 1 */
typedef struct {
        int num_1;
        int num_2;
        int (* add)();
} test_struct;

int add(test_struct * self) {
    return self->num_1 + self->num_2;
}

int initialize_test_str(test_struct * str_pointer, int num_1, int num_2){
	str_pointer-> num_1 = num_1;
	str_pointer-> num_2 = num_2;
	return 0;
}
test_struct thing_1;
test_struct thing_2;

int test1(){
	printf("Hello World");
	int result_1 = 0;
	int result_2 = 0;

	initialize_test_str(&thing_1, 2, 6);
	initialize_test_str(&thing_2, 30, 50);

	result_1 = add(&thing_1);
	result_2 = add(&thing_2);

	printf("result 1 is %d" , result_1);
	printf("result 2 is %d" , result_2);

	return 0;
}

/* Test memory */


int test_memory(){
	memory * mem_ptr = memory_init(25);
	//test size
	mem_ptr->size;
	printf("size of memory is  %d\n" , mem_ptr->size);
	//assign some value
	int index = 2;
	//mem_ptr->shared_memory[index] = 42;

	return 0;
}
	//Consumer/Producer
	// [n] * 50
	//[0, 5, 9, 27]
	// ops = [n, n, n, (a,0), n, n, n, 5.... 27]

	// This is in the CPU
	// Allocate Memory
	// IP = 123123
	// addr = IP % len(ops)

/*	// Allocate
	int addr = 21;
	if (mem_ptr->getLocation(mem_ptr, addr) == 0){
		// proccess blocked
	} else{
		//allocate address
		mem_ptr->setLocation(mem_ptr, addr, 0);
	}

	//De Allocate
	//if (mem_ptr->getLocation(mem_ptr, addr) == 1){
		// proccess blocked
	} else{
		//allocate address
	//	mem_ptr->setLocation(mem_ptr, addr, 0);
	}


	//mem_ptr->setLocation(mem_ptr, index, 56);
	//int location_value = mem_ptr->getLocation(mem_ptr, index);
	printf("value in index %d\n" , location_value);

	return 0;
}*/


int main1(){

	// Find Appropriate Random Number...
//	int no_steps = 100;
//	int max = rand() % no_steps -1;
//	while (1){
//		int address = (no_steps-1) - (rand() % (no_steps - 1 - max));
//		printf("MAX: %d NUM %d",max,  address);
//		if (address <= max){
//			printf("This isn't working");
//		}
//	}
	//test_memory();


	interrupt intr;
	Queue my_interrupt_queue;
	my_interrupt_queue = CreateQueue(100);

	char *process_name = "System Timer";
	char *data = "";
	//interrupt_init(&intr, 2, process_name, data);

	Enqueue(&intr, my_interrupt_queue);

	printf("Hello World\n");
	char myChar;
	unsigned char flag = 0;

	io_device my_keyboard;
	cpu my_cpu;

	//io_device_init(&my_keyboard, &my_cpu, 0);
	return 0;
}

